/* eslint-disable */
/**
 * Created by GYL on 2018/8/24
 */
//事件模板管理
import React, { Component } from 'react';
import Filtrate from '../../../components/common/Filtrate';
import Container from "../../../components/common/Container";
import MyTable from "../../../components/common/MyTable";
import PublicModal from '../../../components/common/PublicModal/index';
import PublicService from "../../../services/PublicService";
import PublicTemplate from '../../../services/PublicTemplate'
import request from '../../../utils/request';
import MyPagination from "../../../components/common/MyPagination";
import config from '../../../config';
import { message, Divider, TagSpi, Switch, Icon, Spin } from 'antd';
import styles from './RoleList.less';
import Edit_Use from './Edit_Use';
var treeArr = []
const IconFont = Icon.createFromIconfontCN({
  scriptUrl: '//at.alicdn.com/t/font_1315525_f8lqdqjh676.js',
});
class RemindSet extends Component {

  state = {
    publicModal: false,
    userId: '',
    EditData: {},
    status: "",
    params: {},
    pageSize: 10,
    pageIndex: 1,
    total: 0,
    delConfirm: false,
    addModal: false,
    selectedRowKeys: [],
    dataSate: [
      {

      }
    ],
    addWrap: true,
    editWrap: false,
    EditArr: [],
    AddArr: [],
    GtteWrapId: '',
    spinning: false,
    planStart: '',
    planEnd: '',
    postponeStart: '',
    startFrequency: '',
    postponeEnd: '',
    endFrequency: '',
    modalBtnLoading:false
  }
  componentDidMount() {
    this.onSubmit()


  }


  //查询
  onSubmit = (page, size) => {
    request({
      url: '/pm-web/projectmanage/remind/findRemindConfiguration',
      method: 'GET',
    }).then(data => {
      if (data.rc === 0) {

        const { planStart, planEnd, postponeStart, startFrequency, postponeEnd, endFrequency } = data.ret

        this.setState({
          planStart, planEnd, postponeStart, startFrequency, postponeEnd, endFrequency
        })
      }
    })
  }


  // 取消保存
  ModalCancel = (type) => {
    let t = this;
    t.setState({
      [type]: false,
      modalBtnLoading: false
    })
  };


  querySystemRoles = (record) => {
    this.setState({
      publicModal: true
    })
  }

  // 关闭模态框
  modalCancel = (type) => {
    this.setState({
      [type]: false,
      record: {}
    });
  };

  onSave = (v) => {
    console.log(v)
    this.setState({
      modalBtnLoading:true
    })
    request({
      url: '/pm-web/projectmanage/remind/updateRemindConfiguration',
      method: 'POST',
      data: {...v}
    }).then(data => {
      if(data.rc === 0) {
        message.success('修改成功!')

        this.onSubmit()
      }else{
        message.warning(data.err)
      }
      this.setState({
        publicModal:false,
        modalBtnLoading:false
      })
    })
  }
  render() {

    let width = document.body.clientWidth;
    const height = document.body.clientHeight;
    const t = this
    let containerHeight = '71vh';
    let tableHeight = 290;
    if (width > 1367) {
      tableHeight = 340;
      containerHeight = '77vh';
    }
    const { pageSize, pageIndex, selectedRowKeys, total, dataSate, delConfirm } = this.state
    const { planStart, planEnd, postponeStart, startFrequency, postponeEnd, endFrequency, publicModal,modalBtnLoading } = this.state

    const data = [
      {
        name: "计划开始前提醒",
        val: planStart,
        type: 'day'
      },
      {
        name: "计划结束前提醒",
        val: planEnd,
        type: 'day'
      },
      {
        name: "逾期开始提醒",
        val: postponeStart,
        type: 'day'
      },

      {
        name: "逾期结束提醒",
        val: postponeEnd,
        type: 'day'
      },
      {
        name: "逾期开始频率",
        val: startFrequency,
        type: 'switch'
      },
      {
        name: "逾期结束频率",
        val: endFrequency,
        type: 'switch'
      }
    ]


    const columns = [
      // { title: '序号', dataIndex: 'num', width: 50, align: 'center' },
      {
        title: '配置项', dataIndex: 'name', key: 'name', width: 100, align: 'center'

      },

      {
        title: '配置内容', dataIndex: 'val', key: 'val', width: 150, align: 'center',
        render: (text, record) => <span>
          {record.type == 'day' ? record.val + '天' : record.val == '1' ? '单次' : '重复'}
        </span>
      },


      {
        title: '操作', dataIndex: 'roleNameStr', key: 'projectNumber', width: 200, align: 'center',
        render: (text, record) => <span>
          <span onClick={this.querySystemRoles.bind(this, data)} style={{ color: '#40a9ff', border: '1px solid #40a9ff', padding: 2, borderRadius: 5, cursor: 'pointer' }}>
            <IconFont type="icon-gantetu" />  编辑
          </span>
        </span>
      },

    ];


    const moddleArr = [

      {
        type: 'select',
        label: '延期结束频率',
        paramName: 'endFrequency',
        initialValue:endFrequency,
        rules: [{ ...config.reg.required }],
        options: [
          { text: '单次', value: 1 },
          { text: '重复', value: 2 },
        ],
        //   disabled,
        span: 12,
      },
      {
        type: 'select',
        label: '延期开始频率',
        paramName: 'startFrequency',
        initialValue:startFrequency,
        rules: [{ ...config.reg.required }],
        options: [
          { text: '单次', value: 1 },
          { text: '重复', value: 2 },
        ],
        //   disabled,
        span: 12,
      },

      {
        type: 'input',
        label: '计划结束前提醒(天)',
        paramName: 'planEnd',
        initialValue:planEnd,
        rules: [{ ...config.reg.absLong2 }],
        //   disabled,
        span: 12,
      },
      {
        type: 'input',
        label: '计划开始前提醒(天)',
        paramName: 'planStart',
        initialValue:planStart,
        rules: [{ ...config.reg.absLong2 }],
        //   disabled,
        span: 12,
      },
      {
        type: 'input',
        label: '延期结束提醒(天)',
        paramName: 'postponeEnd',
        initialValue:postponeEnd,
        rules: [{ ...config.reg.absLong2 }],
        //   disabled,
        span: 12,
      },
      {
        type: 'input',
        label: '延期开始提醒(天)',
        paramName: 'postponeStart',
        initialValue:postponeStart,
        rules: [{ ...config.reg.absLong2 }],
        //   disabled,
        span: 12,
      },


    ]
    return (

      <div style={{ position: 'relative', boxSize: 'border-box', padding: 5, paddingTop: 0, paddingBottom: 0 ,backgroundColor:'#fff',height:'80vh'}}>
        {
          <div style={{ flex: 1 }}>
            <Spin spinning={this.state.spinning} size='large'>
              {
                publicModal &&
                <PublicModal
                  items={moddleArr}
                  modalBtnLoading={modalBtnLoading}
                  wrappedComponentRef={ref => this.myForm = ref}
                  visible={publicModal}
                  title={'编辑'}
                  footerShow={true}
                  onModalSave={t.onSave}
                  onCancel={t.modalCancel.bind(t, 'publicModal')}
                  width={900}
                />
              }


              {/* <div className={styles['RemindSet']}>
                {
                  data.map((item, index) => {
                    return (
                      <div className={styles['RemindSet-box']}>
                        <div className={styles['RemindSet-name']}>{item.name}</div>
                        {
                          item.type == 'day' &&
                          <div className={styles['RemindSet-value']}>{item.value}天</div>
                        }

                        {
                          item.type == 'switch' &&
                          <div className={styles['RemindSet-value']}>{item.value == '1' ? '单次' : '重复'}</div>
                        }

                      </div>
                    )
                  })
                }
              </div> */}
              <MyTable
                // rowSelection={rowSelection}
                scroll={{ y: height - tableHeight }}
                columns={columns}
                dataSource={PublicService.transformArrayData(data, true, true, pageIndex, pageSize)}
                pagination={false}
              />
            </Spin>
          </div>
        }


      </div>
    );


  }
}
export default RemindSet;

